//
//  Tool.m
//  智慧小区
//
//  Created by lab603 on 15/6/29.
//  Copyright (c) 2015年 Dreamsoul. All rights reserved.
//

#import "Tool.h"
@implementation Tool
//设置cookie
+ (void)setCookieWithKey:(NSString*)key Value:(NSString*)value
{
    NSMutableDictionary *cookiePropertiesUser = [NSMutableDictionary dictionary];
    [cookiePropertiesUser setObject:key forKey:NSHTTPCookieName];
    [cookiePropertiesUser setObject:value forKey:NSHTTPCookieValue];
    [cookiePropertiesUser setObject:HOST_DOMAIN forKey:NSHTTPCookieDomain];
    [cookiePropertiesUser setObject:@"/" forKey:NSHTTPCookiePath];
    [cookiePropertiesUser setObject:@"0" forKey:NSHTTPCookieVersion];
    
    NSHTTPCookie *cookieuser = [NSHTTPCookie cookieWithProperties:cookiePropertiesUser];
    [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookieuser];
}
//获取cookie
+ (NSArray *)getCookie
{
    
    NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    
    NSArray *cookieAry = [cookieJar cookiesForURL: [NSURL URLWithString: HOST_URL]];
    
    return cookieAry;
}
//清除cookie
+ (void)deleteCookie
{
    NSHTTPCookie *cookie;
    
    NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    
    NSArray *cookieAry = [cookieJar cookiesForURL: [NSURL URLWithString: HOST_URL]];
    
    for (cookie in cookieAry) {
        
        [cookieJar deleteCookie: cookie];
        
    }
}
+ (MBProgressHUD*)HUDShowMessage:(NSString*)msg addedToView:(UIView*)view
{
    if(view==nil){
        view=[[UIApplication sharedApplication].windows lastObject];
    }
    static MBProgressHUD* hud = nil;
    hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.labelText = msg;
    hud.hidden = NO;
    hud.alpha = 1.0f;
    [hud hide:YES afterDelay:1.0f];
    return hud;
}
+ (void)HUDShowMessage:(NSString*)msg{
    [self HUDShowMessage:msg addedToView:[UIApplication sharedApplication].keyWindow];
}
+ (MBProgressHUD*)HUDShowProgress:(NSString*)msg addedToView:(UIView*)view
{
    if(view==nil){
        view=[[UIApplication sharedApplication].windows lastObject];
    }
    static MBProgressHUD* hud = nil;
    hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeIndeterminate;
    hud.labelText = msg;
    hud.hidden = NO;
    hud.alpha = 1.0f;
    return hud;
}
+ (void)HUDShowProgress:(NSString*)msg{
    [self HUDShowProgress:msg addedToView:[UIApplication sharedApplication].keyWindow];
}
@end
